// 银行卡
// import { isEmpty } from 'lodash'
import * as types from '@/store/mutation-types'
import api from '@/tools/api.js'
import promise from '@/tools/promise'
// import { SUCCESS_STATUS } from '@/config/status'
const state = {
  list: [],
  pageData: {
    total: 1,
    per_page: 15,
    current_page: 1,
    last_page: 1
  },
  saveData: {}
}

// mutations
const mutations = {
  [types.BANK_CARD_LIST] (state, payload) {
    state.list = payload.data
    state.pageData.total = Number(payload.total)
    state.pageData.per_page = Number(payload.per_page)
    state.pageData.current_page = Number(payload.current_page)
    state.pageData.last_page = Number(payload.last_page)
  },
  [types.BANK_CARD_SAVE_DATA] (state, payload) {
    state.saveData = payload
  }
}

// actions
const actions = {
  // 获取银行卡列表
  async cardList ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在获取银行卡列表'}
    let res = await api('serverbankcard/bankcard/Bankcard/cardList', payload, config)
    commit(types.BANK_CARD_LIST, res.res)
  },
  // 审核银行卡
  async audit ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在审核银行卡'}
    let res = await api('serverbankcard/bankcard/Bankcard/audit', payload, config)
    return promise(res)
  },
  // 删除银行卡
  async delCard ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在删除银行卡'}
    let res = await api('serverbankcard/bankcard/Bankcard/AdminDelCard', payload, config)
    return promise(res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
